//
//  SYMainTableViewCell.m
//  TermOfSectionB
//
//  Created by dlios on 15/11/30.
//  Copyright © 2015年 韩震明. All rights reserved.
//

#import "SYMainTableViewCell.h"
#import "SYMainCollectionViewCell.h"
#import "SYMainTableViewModel.h"
@interface SYMainTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, strong) NSMutableArray *firstArray;

@end

@implementation SYMainTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
    }
    
    return self;
}

// 创建CollectionView
- (void)createCollectionView {
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(72, 105);
    
    self.mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 375, 250) collectionViewLayout:flowLayout];
    [self.contentView addSubview:self.mainCollectionView];
    
    self.mainCollectionView.backgroundColor = [UIColor whiteColor];
    
    // 注册collectionViewCell的方法
    [self.mainCollectionView registerClass:[SYMainCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    flowLayout.sectionInset = UIEdgeInsetsMake(20, 5, 2, 2);
    self.mainCollectionView.dataSource = self;
    self.mainCollectionView.delegate = self;
    
}

// collectionView每个分区中的Item数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 7;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    // 创建collectionViewCell的过程
    SYMainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    
    SYMainTableViewModel *pic = self.mainArray[indexPath.row];
    
    cell.mainLabel.text = pic.name;
    
    [cell.mainPictureImageView sd_setImageWithURL:[NSURL URLWithString:pic.logo]];
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    SYMainTableViewModel *model = self.mainArray[indexPath.row];
    
    // 3.在设置代理人属性的.m文件中去执行这个方法
    [self.delegate pushIndexID:model.picID withName:model.name];
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
